package d1_wd;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


class NumberThread implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                if (i % 2 == 0) {
                    System.out.println(Thread.currentThread().getName() + ":\t" + i);
                }
            }
        }
    }

    public class t6Threads {
        public static void main(String[] args) {

            //1.提供指定线程数量的线程池
            ExecutorService service = Executors.newFixedThreadPool(10);
            ThreadPoolExecutor service1 = (ThreadPoolExecutor) service;
            //设置线程池的属性
                    System.out.println(service.getClass());
                    service1.setCorePoolSize(15);
                    service1.setKeepAliveTime(10, TimeUnit.SECONDS);

//            2.执行指定的线程的操作。需要提供实现Runnable接口或Callable接口实现类的对象。
            service.execute(new NumberThread()); //适合用于Runnable
            //        service.submit(); 适合适用于Callable
            //关闭线程池
            service.shutdown();
        }
    }

